<template>
  <div class="rune-detail">
    <!-- 返回按钮 -->
    <div class="back-button" @click="goBack">
      <el-icon><ArrowLeft /></el-icon>
      返回
    </div>
    
    <!-- 符文内容 -->
    <div class="rune-content">
      <div class="rune-main">
        <div class="rune-image">
          <img :src="runeDetail.img" :alt="runeDetail.name" v-if="runeDetail.img" />
          <img src="../assets/default_rune.png" :alt="runeDetail.name" v-else />
        </div>
        
        <div class="rune-info">
          <h1>{{ runeDetail.name }}</h1>
          <div class="grade">
            <span :class="getGradeClass(runeDetail.grade)">{{ runeDetail.grade }}</span>
          </div>
          <div class="effect">{{ runeDetail.effect }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElLoading } from 'element-plus'
import { ArrowLeft } from '@element-plus/icons-vue'
import RuneAPI from '@/api/rune.api'

const route = useRoute()
const router = useRouter()
const runeId = ref(route.query.id)
const runeDetail = ref({})

// 获取符文详情
const fetchRuneDetail = async () => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(0, 0, 0, 0.7)',
  })
  
  try {
    const response = await RuneAPI.getRune(runeId.value)
    if (response) {
      runeDetail.value = response
    }
  } catch (error) {
    console.error('获取符文详情失败', error)
  } finally {
    loading.close()
  }
}

// 根据等级返回样式类
const getGradeClass = (grade) => {
  if (!grade) return ''
  
  switch (grade) {
    case '金':
      return 'gold'
    case '银':
      return 'silver'
    case '彩':
      return 'rainbow'
    default:
      return ''
  }
}

// 返回上一页
const goBack = () => {
  router.go(-1)
}

onMounted(() => {
  fetchRuneDetail()
})
</script>

<style scoped>
.rune-detail {
  position: relative;
  min-height: 100vh;
  color: white;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rune-detail::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('../assets/heard(2).png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  opacity: 0.3;
  z-index: -1;
}

.back-button {
  display: inline-flex;
  align-items: center;
  padding: 10px 15px;
  background: rgba(0, 163, 131, 0.8);
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 20px;
  transition: background 0.3s;
  z-index: 10;
  position: relative;
  align-self: flex-start;
}

.back-button:hover {
  background: rgba(0, 163, 131, 1);
}

.rune-content {
  max-width: 800px;
  width: 100%;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 10px;
  padding: 30px;
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rune-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  margin-bottom: 30px;
  padding-bottom: 30px;
  border-bottom: 1px solid #00a383;
  width: 100%;
}

.rune-image {
  display: flex;
  justify-content: center;
}

.rune-image img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border: 3px solid #00a383;
  border-radius: 10px;
}

.rune-info {
  flex: 1;
  width: 100%;
  text-align: center;
}

.rune-info h1 {
  font-size: 36px;
  margin-bottom: 20px;
  color: #00a383;
}

.grade {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
}

.grade span {
  padding: 5px 15px;
  border-radius: 20px;
  font-weight: bold;
}

.grade .gold {
  background: linear-gradient(45deg, #FFD700, #FFA500);
  color: #000;
}

.grade .silver {
  background: linear-gradient(45deg, #C0C0C0, #A9A9A9);
  color: #000;
}

.grade .rainbow {
  background: linear-gradient(45deg, #FF0000, #FF7F00, #FFFF00, #00FF00, #0000FF, #4B0082, #9400D3);
  color: #fff;
}

.effect {
  white-space: pre-line;
  line-height: 1.6;
  margin-bottom: 25px;
  font-size: 18px;
  padding: 15px;
  background: rgba(0, 163, 131, 0.1);
  border-radius: 10px;
  text-align: center;
}

@media (max-width: 768px) {
  .rune-main {
    flex-direction: column;
  }
  
  .rune-image img {
    width: 150px;
    height: 150px;
  }
  
  .rune-info h1 {
    font-size: 28px;
  }
}
</style>
